using Nop.Core.Domain.Catalog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Core.ApiDataModel.Catalog
{
	public partial class ProductVariantAttributeModel
	{
		public int Id { get; set; }	

		public string TextPrompt { get; set; }

		public bool IsRequired { get; set; }

		public int ControlTypeId { get; set;  }

		public int DisplayOrder {get;set;}

		public IEnumerable<ProductVariantAttributeValueModel> Values { get; set; }

		public ProductVariantAttributeModel(ProductVariantAttribute attribute)
		{			
			Id = attribute.Id;
			TextPrompt = attribute.TextPrompt;
			IsRequired = attribute.IsRequired;
			ControlTypeId = (int)MapControlTypeId(attribute.AttributeControlTypeId);
			DisplayOrder = attribute.DisplayOrder;
			Values = attribute.ProductVariantAttributeValues.Select(av=> new ProductVariantAttributeValueModel(av));
		}

		private ApiControlType MapControlTypeId(int SystemControlTypeId)
		{
			switch (SystemControlTypeId)
			{ 
				case 1:
				case 2:
					return ApiControlType.SingleSelect;
				case 3:
					return ApiControlType.MultiSelect;
				case 4:
				case 10:
					return ApiControlType.FreeText;
				case 20:
					return ApiControlType.DatePicker;
			}
			return ApiControlType.None;
		}
	}

	public enum ApiControlType
	{
		None         = 0,
		SingleSelect = 1,
		MultiSelect  = 2,
		FreeText     = 3,
		DatePicker   = 4
	}
}
